package com.toobigtofail.enitities
{
	import com.toobigtofail.shapes.IShape;
	
	import fabulaexmachina.box2fp.Box2DEntity;
	import fabulaexmachina.box2fp.Box2DWorld;
	import fabulaexmachina.box2fp.graphics.SuperGraphiclist;
	
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	
	public class Rock extends Box2DEntity
	{
		[Embed(source="/assets/gfx/rock.png")] private static const ROCK_PNG:Class;
		
		public static const TYPE:String = "enemy";
		
		private var _shape:IShape;
		
		private var _initOptions:Object;
		
		public function Rock(shape:IShape, angleRadicals:Number=0)
		{
			_shape = shape;
			_initOptions = {angleRads: angleRadicals}
			super(shape.X, shape.Y, shape.Height, shape.b2Type);
			
			var img:Image = new Image(ROCK_PNG);
			//
			//trace("img width: " + img.width + ", shape width: " + _shape.Width*(FP.world as Box2DWorld).scale + ", scale: " + img.scale);
			img.x = (img.width/-2);
			img.y = (img.height/-2);
			img.scale = (_shape.Width*(FP.world as Box2DWorld).scale)/img.width;
			img.centerOrigin();
			//img.x = img.x - (img.x/img.scale);
			//img.y = img.y - (img.y/img.scale);
			(graphic as SuperGraphiclist).add(img);
			
			
			type = TYPE;
		}
		
		override public function update():void {
			super.update();
			
			if (y < -20) {
				remove();
			}
		}
		
		override public function added():void
		{
			super.added();
			//angleRads = _initOptions.angleRads;
		}
		override public function buildShapes(friction:Number, 
											 density:Number, restitution:Number,
											 group:int, category:int, collmask:int):void { 
			_shape.buildShape(body);
		}
	}
}